package leetcode.dynamic.marscode;

public class DNADist {

    public static int solution(String dna1, String dna2) {
        int[][] dp = new int[dna1.length() + 1][dna2.length() + 1];
        for (int i = 0; i <= dna1.length(); i++) { //dp[i][j] 代表dna1的前i-1个字符变成dna2前j-1个字符所需的最小步数
            dp[i][0] = i; //需要i此删除
        }
        for (int i = 0; i <= dna2.length(); i++) {
            dp[0][i] = i;//需要i次新增
        }
        for (int i = 1; i <= dna1.length(); i++) {
            for (int j = 1; j <= dna2.length(); j++) {
                if (dna1.charAt(i-1) == dna2.charAt(j-1)) {
                    dp[i][j] = dp[i-1][j-1];
                } else {
                    dp[i][j] = Math.min(dp[i-1][j], Math.min(dp[i][j-1], dp[i-1][j-1])) + 1;
                }
            }
        }
        return dp[dna1.length()][dna2.length()];
    }

    public static void main(String[] args) {
        //  You can add more test cases here
        System.out.println(solution("AGCTTAGC", "AGCTAGCT") == 2);
        System.out.println(solution("AGCCGAGC", "GCTAGCT") == 4);
    }

}
